/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			main.cc
  \date			Jul 2011
  \author		TNick

  \brief		Contains application's entry point


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n
 Please read ReadMe.txt and Licence.txt in root folder @n
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include    <QApplication>
#include    <QMessageBox>
#include    <QTimer>
#include    <QNetworkDiskCache>
#include    <QDesktopServices>


#include    <gui/mainwindow.h>
#include    <QtNetwork/QNetworkAccessManager>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

MainWindow *                g_MW;
/// application wide network manager
QNetworkAccessManager *     l_manager ;
/// timer object that is used to check a page on a regular basis
QTimer *                    app_timer;
/// application wide network manager
QNetworkDiskCache *         main_cache ;

/*  DATA    ================================================================ */
//
//
//
//
/*  FUNCTIONS    ----------------------------------------------------------- */


/* ------------------------------------------------------------------------- */
int			main				(int argc, char *argv[])
{
    try
    {
        /* prepare to start */
        QApplication apl(argc, argv);


        /* prepare the ground for easy access to settings */
        QCoreApplication::setOrganizationName("TNick");
        QCoreApplication::setOrganizationDomain("sites.google.com/site/tnickweb/");
        QCoreApplication::setApplicationName("PasteBinSearch");

        /* create network manager that will be used by this application */
        l_manager = new QNetworkAccessManager(qApp);
        main_cache = new QNetworkDiskCache(qApp);
        main_cache->setCacheDirectory(
                    QDesktopServices::storageLocation(
                        QDesktopServices::CacheLocation));
        l_manager->setCache(main_cache);

        app_timer = new QTimer(l_manager);

        /* show main interface */
        g_MW = new MainWindow();
        g_MW->show();

        /* run */
        unsigned uAppErrCode = apl.exec();

//        if (l_manager != NULL)
//            delete l_manager;
//        if (app_timer != NULL)
//            delete app_timer;

        /* exit */
        return uAppErrCode;

    }
    catch(...)
    {
        QMessageBox::critical(0,
                              QObject::tr("Exception!!!"),
                              QObject::tr("Execution cannot continue.\n"
                                          "An exception has been encountered.")
                              );

        return -1;
    }
}
/* ========================================================================= */

/*  FUNCTIONS    =========================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
